{% extends "layout.html" %}
{% block __data_browser__custom_external_block %}
  {{ super() }}
  <link rel="stylesheet" href="{{ url_for('static', filename="css/customer.css") }}" media="print">
  <script type="text/javascript" src="{{ url_for("static", filename="js/jquery-1.8.3.min.js") }}"></script>
  <script type="text/javascript" src="{{ url_for("static", filename="js/jquery-printarea.js") }}"></script>
  <script type="text/javascript">
    $(function () {
      $("#print").click(function () {
        $("#print-area").printArea();
      });
    });
  </script>
{% endblock %}

{% block body %}
  <div class="row">
    {% if error_message %}
      <div class="alert">
        <p class="text-danger">{{ error_message }}</p>
      </div>
    {% endif %}
    <div class="col-lg-12 text-center">
      <button class="btn btn-primary btn-lg" id="print">打印</button>
      <a href="{{ url }}" class="btn btn-default btn-lg">返回</a>
    </div>

    <div id="print-area">
      {% for consignment in consignment_list %}
        {% for entries in consignment.product_list|batch(per_page) %}
          <div class="page-next">
            <div class="col-lg-6 col-lg-offset-3">
              <h5 class="pull-right">NO. {{ consignment.id }}</h5>
              <table class="table table-striped table-bordered table-condensed">
                <tr>
                  <th colspan="5"><h4 class="text-center">金禾域加工发货单</h4></th>
                </tr>
                <tr>
                  <th>发货单号</th>
                  <td colspan="4"><p
                      class="center">{{ consignment.consignment_id }}</p>
                  </td>
                </tr>
                <tr>
                  <th>公司名称</th>
                  <td colspan="4"><p
                      class="center">{{ consignment.customer.name }}</p>
                  </td>
                </tr>
                <tr>
                  <th>车辆车牌号</th>
                  <td colspan="4"><p
                      class="center">{{ consignment.plate }}</p></td>
                </tr>
                <tr>
                  <th>日期</th>
                  <td colspan="4"><p
                      class="center">{{ consignment.create_time.date() }}</p>
                  </td>
                </tr>
                <tr>
                  <th>产品名称</th>
                  {% if consignment.measured_by_weight %}
                    <th colspan="3">净重(公斤)</th>
                  {% else %}
                    <th>规格-型号</th>
                    <th>数量</th>
                    <th>净重(公斤)</th>
                  {% endif %}
                  <th>生产班组</th>
                </tr>
                {% for product in entries %}
                  <tr>
                    <td>{{ product.product.name }}</td>
                    {% if  consignment.measured_by_weight %}
                      <td colspan="3">
                        {{ product.weight }}
                        {% if product.returned_weight %}
                          (退镀{{ product.returned_weight }}KG)
                        {% endif %}
                      </td>
                    {% else %}
                      <td>{{ product.spec + "-" + product.type }}</td>
                      <td>{{ product.quantity }}({{ product.unit }})</td>
                      <td>
                        {{ product.weight }}
                        {% if product.returned_weight %}
                          (退镀{{ product.returned_weight }}KG)
                        {% endif %}
                      </td>
                    {% endif %}
                    <td>
                      {{ product.team.name }}
                    </td>
                  </tr>
                {% endfor %}
                <tr>
                  <th>备注：</th>
                  <td colspan="4">{{ consignment.notes or "" }}</td>
                </tr>
                <tr>
                  <td colspan="3">客户签名：</td>
                  <td colspan="2">
                    总重量(公斤):{{ consignment.product_list|sum(attribute='weight') }}</td>
                </tr>
              </table>
              <p class="text-right">注:若有质量疑义，请在收货之日起三日内以书面形式告知</p>
            </div>
          </div>
        {% endfor %}
      {% endfor %}
    </div>
  </div>
{% endblock %}
